﻿using System;
using System.Diagnostics;
using System.Web.Mvc;
using System.Web.Routing;
using StructureMap;

namespace EnetaMvc.Web
{
    public class StructureMapControllerFactory : DefaultControllerFactory
    {
        protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
        {
            if (controllerType == null)
                return null;

            try
            {
                var controller = ObjectFactory.GetInstance(controllerType);
                return controller as Controller;
            }
            catch
            {
                throw;
            }
        }
    }
}